﻿using System;
using Terraria.Social;

namespace Terraria.Achievements
{
	// Token: 0x020004A7 RID: 1191
	public abstract class AchievementTracker<T> : IAchievementTracker
	{
		// Token: 0x170002DB RID: 731
		// (get) Token: 0x060027DE RID: 10206 RVA: 0x0001BEFF File Offset: 0x0001A0FF
		public T Value
		{
			get
			{
				return this._value;
			}
		}

		// Token: 0x170002DC RID: 732
		// (get) Token: 0x060027DF RID: 10207 RVA: 0x0001BF07 File Offset: 0x0001A107
		public T MaxValue
		{
			get
			{
				return this._maxValue;
			}
		}

		// Token: 0x060027E0 RID: 10208 RVA: 0x0001BF0F File Offset: 0x0001A10F
		protected AchievementTracker(TrackerType type)
		{
			this._type = type;
		}

		// Token: 0x060027E1 RID: 10209 RVA: 0x0001BF1E File Offset: 0x0001A11E
		void IAchievementTracker.ReportAs(string name)
		{
			this._name = name;
		}

		// Token: 0x060027E2 RID: 10210 RVA: 0x0001BF27 File Offset: 0x0001A127
		TrackerType IAchievementTracker.GetTrackerType()
		{
			return this._type;
		}

		// Token: 0x060027E3 RID: 10211 RVA: 0x004955B4 File Offset: 0x004937B4
		void IAchievementTracker.Clear()
		{
			this.SetValue(default(T), true);
		}

		// Token: 0x060027E4 RID: 10212 RVA: 0x004955D4 File Offset: 0x004937D4
		public void SetValue(T newValue, bool reportUpdate = true)
		{
			if (!newValue.Equals(this._value))
			{
				this._value = newValue;
				if (reportUpdate)
				{
					this.ReportUpdate();
					if (this._value.Equals(this._maxValue))
					{
						this.OnComplete();
					}
				}
			}
		}

		// Token: 0x060027E5 RID: 10213
		public abstract void ReportUpdate();

		// Token: 0x060027E6 RID: 10214
		protected abstract void Load();

		// Token: 0x060027E7 RID: 10215 RVA: 0x0001BF2F File Offset: 0x0001A12F
		void IAchievementTracker.Load()
		{
			this.Load();
		}

		// Token: 0x060027E8 RID: 10216 RVA: 0x0001BF37 File Offset: 0x0001A137
		protected void OnComplete()
		{
			if (SocialAPI.Achievements != null)
			{
				SocialAPI.Achievements.StoreStats();
			}
		}

		// Token: 0x040043F7 RID: 17399
		protected T _value;

		// Token: 0x040043F8 RID: 17400
		protected T _maxValue;

		// Token: 0x040043F9 RID: 17401
		protected string _name;

		// Token: 0x040043FA RID: 17402
		private TrackerType _type;
	}
}
